
function puntoa_media
clear all
REALIZATIONS = 20;
DAYS=30;


% Calculo de la media

meanBenefit=[];

for r=1:REALIZATIONS
    meanBenefit(r)= mean(benefits(DAYS));
end
r=1:REALIZATIONS;
meanBenefit
% figure;
% 
% partialMean=partialMean(meanBenefit);
% plot(r,partialMean);
% title('Beneficio');


  
% Calculo de la varianza

varBenefit=[];

% for r=1:REALIZATIONS
%     varBenefit(r)= varianza(partialMean);
% end
for r=1:REALIZATIONS
    varBenefit(r)= partialVar(meanBenefit);
end
r=1:REALIZATIONS;

figure;

plot(r,varBenefit);
title('Varianza');


function ans=partialMean(meanBenefit)
ans=[];
for m=1:size(meanBenefit,2)
    ans(m)=mean(meanBenefit(1,1:m));
end



function ans=partialVar(meanBenefit)
ans=[];
8
for m=1:size(meanBenefit,2)
    meanBenefit(:,1:m)
    ans(m)=mean((meanBenefit(:,1:m)).^2) - (mean(meanBenefit(:,1:m)))^2;
end

% function ans=varianza(data)
%     ans=mean(data.^2)-mean(data)^2;

function data=benefits(days)

p0=100;
data=[];
before=p0;

for d=1:days
    
    random=OurUniformRandom(314159265);
    delta=0;
    
    
    
    if(0<=random && random< 3/36)
        delta=-1/8;
    elseif(3/36  <= random && random < 10/36)
        delta=0;
    elseif(10/36 <= random && random < 26/36)
        delta=1/8;
    elseif(26/36 <= random && random < 34/36)
        delta=1/2;
    elseif(34/36 <= random && random < 1)
        delta=1;
    end
    
    data(d)=before+delta;
    before=data(d);
end


data=data-p0;





